<template>
  <div class="login_view">
    <div class="login_container">
      <div class="avatar_box">
        <img src="../assets/logo.png" alt="avatar" />
      </div>
      <el-form label-width="60px" class="login_form" :model="LoginValue" :rules="rules" ref="LoginValue">
        <el-form-item label="账号" prop="userName">
          <el-input v-model="LoginValue.userName"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="LoginValue.password" type="password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="Login">登录</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>


import {login} from "@/api/user";

export default{
  data() {
    return {
      LoginValue: {
        userName: '',
        password: ''
      },
      rules: {
        userName: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 15, message: '用户名长度为3到15个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 5, max: 15, message: '密码长度为5到15个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    Login() {
      this.$refs.LoginValue.validate( (valid) => {
        login(this.LoginValue).then(res=>{
          if (res.code===200){
            window.localStorage.setItem("aid",res.msg);
            this.$router.push('/home')
          }
        })
      })
    },
    reset() {
      this.$refs.LoginValue.resetFields();
    }
  }
}
</script>

<style lang="less" scoped>
.login_view {
  background-color: #2c3e50;
  height: 100%;
  .login_container {
    position: absolute;
    width: 450px;
    height: 300px;
    border-radius: 3px;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    background-color: #fff;
    border: 1px solid #fff;
  }
  .avatar_box {
    height: 130px;
    width: 130px;
    border-radius: 50%;
    box-shadow: 0 0 10px #ddd;
    border: 1px solid #eee;
    background-color: #fff;
    position: absolute;
    padding: 10px;
    left: 50%;
    transform: translate(-50%, -50%);
    img {
      height: 100%;
      width: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
  .login_form {
    position: absolute;
    margin-top: 90px;
    width: 95%;
    box-sizing: border-box;
    .el-form-item {
      height: 50px;
    }
    .el-button{
      width: 25%;
      height: 80%;
    }
  }
}
</style>
